package com.github.easyms.server.controller.auth;

import com.github.easyms.common.base.BaseController;
import com.github.easyms.common.entity.auth.Role;
import com.github.easyms.common.entity.auth.User;
import com.github.easyms.common.vo.PageParams;
import com.github.easyms.common.vo.ResultPage;
import com.github.easyms.server.service.auth.RoleService;
import io.swagger.annotations.Api;
import org.apache.shiro.SecurityUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 角色管理接口
 *
 * @author Leo.Liao
 * @date 2020-05-21 15:22:17
 */
@Api(tags = "角色管理接口")
@RestController
@RequestMapping("/api/auth/role")
public class RoleController extends BaseController<Role> {

    @Resource
    private RoleService roleService;

    @Override
    public ResponseEntity<ResultPage<Role>> list(PageParams pageParams, Role conditions) {
        service = roleService;
        return super.list(pageParams, conditions);
    }

    @Override
    public ResponseEntity<Role> insert(@RequestBody Role entity) {
        service = roleService;
        User currentUser = (User) SecurityUtils.getSubject().getPrincipal();
        entity.setEditUser(currentUser.getUserId());
        return super.insert(entity);
    }

    @Override
    public ResponseEntity<Role> update(@RequestBody Role entity) {
        service = roleService;
        User currentUser = (User) SecurityUtils.getSubject().getPrincipal();
        entity.setEditUser(currentUser.getUserId());
        return super.update(entity);
    }

    @Override
    public ResponseEntity<Role> delete(@RequestBody Role entity) {
        service = roleService;
        return super.delete(entity);
    }

    @Override
    public ResponseEntity<List<Role>> listCombobox(Role entity,String q) {
        return ResponseEntity.ok(roleService.listCombobox(entity,q));
    }
}
